from django.urls import include, path
from knox.views import LogoutAllView, LogoutView
from rest_framework import routers

from main.views import (
    assembly,
    attachment,
    attachment_groups,
    auth,
    client,
    contract,
    delivery,
    measuresheet,
    order,
    reclamation,
    request,
    task,
    warranty,
    worker,
)

router = routers.SimpleRouter()
router.register(r"requests", request.RequestViewSet)
router.register(r"clients", client.ClientViewSet)
router.register(r"orders", order.OrderViewSet)
router.register(r"contracts", contract.ContractViewSet)
router.register(r"measuresheets", measuresheet.MeasureSheetViewSet)
router.register(r"warranties", warranty.WarrantyViewSet)
router.register(r"reclamations", reclamation.ReclamationViewSet)
router.register(r"tasks", task.TaskViewSet)
router.register(r"workers", worker.WorkerViewSet)
router.register(r"assemblies", assembly.AssemblyViewSet)
router.register(r"deliveries", delivery.DeliveryViewSet)
router.register(
    r"attachments/groups", attachment_groups.AttachmentGroupsViewSet
)
router.register(r"attachments", attachment.AttachmentViewSet)

urlpatterns = [
    path(r"api/v1/auth/login/", auth.LoginAPIView.as_view(), name="knox_login"),
    path(r"api/v1/auth/logout/", LogoutView.as_view(), name="knox_logout"),
    path(
        r"api/v1/auth/logoutall/",
        LogoutAllView.as_view(),
        name="knox_logout_all",
    ),
    path(r"api/v1/auth/whoami/", auth.WhoAmIView.as_view(), name="whoami"),
    path(
        r"api/v1/attachments/<int:pk>/file",
        attachment.view_attach,
        name="view_attach",
    ),
    path("api/v1/", include(router.urls)),
]
